﻿#region Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.

// ==================================================================================================
// Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME	:   iConnect.Azure Application Framework
// COMPONENT ID :   NCS.IConnect.Azure.Diagnostics.AzureStorage.AzureStorageCloudTableClient
// COMPONENT DESC:  	
//
// CREATED DATE/BY:  08 June 2012 / Lu Ya Ming
//
// REVISION HISTORY:	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

#endregion

using Microsoft.WindowsAzure.StorageClient;

namespace NCS.IConnect.Cloud.Core.AzureStorage
{
    /// <summary>
    /// The Azure storage cloud table client.
    /// </summary>
    public class AzureStorageCloudTableClient : ICloudTableClient
    {
        private readonly CloudTableClient tableClient;

        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageCloudTableClient"/> class.
        /// </summary>
        /// <param name="tableClient">The table client.</param>
        public AzureStorageCloudTableClient(CloudTableClient tableClient)
        {
            this.tableClient = tableClient;
        }

        /// <summary>
        /// Gets the data service context.
        /// </summary>
        /// <returns></returns>
        public ITableServiceContext GetDataServiceContext()
        {
            return new AzureStorageTableServiceContext(this.tableClient.GetDataServiceContext());
        }

        /// <summary>
        /// Creates the table if not exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        public void CreateTableIfNotExist(string tableName)
        {
            this.tableClient.CreateTableIfNotExist(tableName);
        }

        /// <summary>
        /// Deletes the table if exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        public void DeleteTableIfExist(string tableName)
        {
            this.tableClient.DeleteTableIfExist(tableName);
        }

        /// <summary>
        /// Doeses the table exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        public bool DoesTableExist(string tableName)
        {
            return this.tableClient.DoesTableExist(tableName);
        }
    }
}
